package com.keba.lamp.ai.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.keba.basic.interfaces.echo.EchoService;
import com.keba.lamp.ai.entity.AiCustomer;
import com.keba.lamp.ai.entity.AiModel;
import com.keba.lamp.ai.entity.AiModelVersion;
import com.keba.lamp.ai.service.AiCustomerService;
import com.keba.lamp.ai.service.AiModelService;
import com.keba.lamp.ai.service.AiModelVersionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import com.keba.basic.base.controller.SuperController;
import com.keba.lamp.ai.service.AiEndPointService;
import com.keba.lamp.ai.entity.AiEndPoint;
import com.keba.lamp.ai.vo.save.AiEndPointSaveVO;
import com.keba.lamp.ai.vo.update.AiEndPointUpdateVO;
import com.keba.lamp.ai.vo.result.AiEndPointResultVO;
import com.keba.lamp.ai.vo.query.AiEndPointPageQuery;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * 接入点
 * </p>
 *
 * @author twg
 * @date 2025-03-02 19:38:54
 * @create [2025-03-02 19:38:54] [twg] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/aiEndPoint")
@Tag(name = "接入点")
public class AiEndPointController extends SuperController<AiEndPointService, Long, AiEndPoint
        , AiEndPointSaveVO, AiEndPointUpdateVO, AiEndPointPageQuery, AiEndPointResultVO> {
    private final EchoService echoService;

    private final AiCustomerService aiCustomerService;

    private final AiModelService aiModelService;
    private final AiModelVersionService aiModelVersionService;

    @Override
    public EchoService getEchoService() {
        return echoService;
    }


    @Override
    public void handlerResult(IPage<AiEndPointResultVO> page) {
        page.getRecords().forEach(item -> {
            AiModel aiModel = aiModelService.getById(item.getModelId());
            if (aiModel != null) {
                item.getEchoMap().putIfAbsent("modelId", aiModel.getModelName());
            }
            AiCustomer aiCustomer = aiCustomerService.getById(item.getCustomerId());
            if (aiCustomer != null) {
                item.getEchoMap().putIfAbsent("customerId", aiCustomer.getName());
            }
            AiModelVersion aiModelVersion = aiModelVersionService.getById(item.getModelVersionId());
            if (aiModelVersion != null) {
                item.getEchoMap().putIfAbsent("modelVersionId", aiModelVersion.getName());
            }
        });
    }
}


